package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.RadioPageAlbumData;
import com.rjwh.dingdong.client.util.ViewHolder;
import com.rjwh.dingdong.client.widget.RoundImageView;

/**
 * @author Kay
 * @ClassName RadioAlbumListAdapter
 * @Description 听听推荐专辑列表
 * @date 2016-10-26
 * @history 2016-10-26 author: description:
 */

public class RadioAlbumListAdapter extends AdapterBase<RadioPageAlbumData> {

    private Context mContext;
    private boolean isMainPage;

    public RadioAlbumListAdapter(Context mContext, boolean isMainPage) {
        this.mContext = mContext;
        this.isMainPage = isMainPage;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.radio_album_list_item, null);
        }

        RoundImageView radioAlbumListItemImg = ViewHolder.get(convertView, R.id.radio_album_list_item_img);
        TextView radioAlbumListItemTitleTv = ViewHolder.get(convertView, R.id.radio_album_list_item_title_tv);
        TextView radioAlbumListItemSubtitleTv = ViewHolder.get(convertView, R.id.radio_album_list_item_subtitle_tv);
        TextView radioAlbumListItemContentTv = ViewHolder.get(convertView, R.id.radio_album_list_item_content_tv);
        TextView radioAlbumListItemAuditionTv = ViewHolder.get(convertView, R.id.radio_album_list_item_audition_tv);
        TextView radioAlbumListItemLikeTv = ViewHolder.get(convertView, R.id.radio_album_list_item_like_tv);
        View topDivider = ViewHolder.get(convertView, R.id.radio_album_list_item_top_divider);
        View bottomDivider = ViewHolder.get(convertView, R.id.radio_album_list_item_bottom_divider);

        RadioPageAlbumData radioPageAlbumData = getList().get(position);

        if (isMainPage) {
            topDivider.setVisibility(View.VISIBLE);
            bottomDivider.setVisibility(View.GONE);
        } else {
            bottomDivider.setVisibility(View.VISIBLE);
            topDivider.setVisibility(View.GONE);
        }

        if (radioPageAlbumData == null) {
            return convertView;
        }

        String coverurl = radioPageAlbumData.getCoverurl();
        String albumname = radioPageAlbumData.getAlbumname();
        String description = radioPageAlbumData.getDescription();
        String hotprogram = radioPageAlbumData.getHotprogram();
        String playcount = radioPageAlbumData.getPlaycount();
        String goodcount = radioPageAlbumData.getGoodcount();

        if (!AsStrUtils.isEmpty(albumname)) {
            radioAlbumListItemTitleTv.setText(albumname);
        }
        if (!AsStrUtils.isEmpty(description)) {
            radioAlbumListItemSubtitleTv.setText(description);
        }
        if (!AsStrUtils.isEmpty(hotprogram)) {
            radioAlbumListItemContentTv.setText(hotprogram);
        }
        if (!AsStrUtils.isEmpty(playcount)) {
            radioAlbumListItemAuditionTv.setText(playcount);
        }
        if (!AsStrUtils.isEmpty(goodcount)) {
            radioAlbumListItemLikeTv.setText(goodcount);
        }

        Glide.with(mContext).load(coverurl).dontAnimate().placeholder(R.drawable.icon_pic_holder).error(R.drawable.icon_pic_holder)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(radioAlbumListItemImg);

        return convertView;
    }
}
